package com.muchfish.reactor.api;

import reactor.core.publisher.Flux;

import java.util.function.Function;

public class ReactorTransformExample {
    public static void main(String[] args) {
        Flux<Integer> source = Flux.range(1, 5);

        // 定义一个操作链
        Function<Flux<Integer>, Flux<Integer>> customTransform = flux ->
                flux.filter(x -> x % 2 == 0)
                        .map(x -> x * 2);

        // 使用 transform 应用自定义操作链
        source.transform(customTransform)
                .subscribe(System.out::println); // 输出: 4, 8
    }
}

